#!/bin/sh
###################
source /etc/profile
source /root/.bash_profile
##################
cd `dirname $0`
#质量报告诊报告学院/课程/专业/教师/学生层面数据项定时脚本 学年学期

#所执行的脚本学院层面
REPORT_COLLEGE=qu_college_student_quality_report.sh
#所执行的脚本学院层面（里面的方法）
SHELL_COLLEGE="
Total_number_of_students_in_school
Student_to_Teacher_Ratio
Counselor_student_teacher_ratio
Number_of_courses_offered
Number_of_theoretical_courses
Proportion_of_theoretical_courses
Theory_and_Practice_Course
Proportion_of_theoretical_and_practical_courses
Number_of_Practice_Courses
Proportion_of_Practice_Courses
School_Enterprise_Cooperative_Development_Course
Student_teacher_ratio
The_Situation_of_Student_Teacher_Ratio_of_Counselors
Total_planning
Planned_Quantity_Completed
Uncompleted_Planning_Quantity
Number_of_completed_tasks
Total_number_of_planning_tasks
Total_number_of_plans_except_for_Colleges
Planning_at_all_levels_except_the_College_has_been_completed
Planning_at_all_levels_except_the_College_is_not_completed
Number_of_Quality_Control_Points_at_Five_Levels
Quality_Control_Points_at_College_Level
Quality_Control_Points_for_Achieving_Standards_at_Five_Levels
Total_number_of_levels_other_than_college
Total_task
Number_of_tasks_completed
Task_completion_rate
"
#所执行的脚本课程层面
REPORT_COURSE=qu_course_quality_report.sh
#所执行的脚本课程层面（里面的方法）
SHELL_COURSE="
import_table_KSKCSL
import_table_LLLKCSL
import_table_LLLCCSLKSKCSLZB
import_table_LLJSJLCSL
import_table_LLJSJLCSLKCSLZB
import_table_SJKCSL
import_table_SJKCSLKCSLZB
import_table_XQHZKFKCS
import_table_GHZS
import_table_YWCGHSL
import_table_WWCGHSL
import_table_YWCRWSL
import_table_JSCMGHRSZS
import_table_GHRWWCL
import_table_ZKDSL
"
#所执行的脚本专业层面
REPORT_MAJOR=qu_major_quality_report.sh
#所执行的脚本专业层面 （里面的方法）
SHELL_MAJOR="
import_table_GHZS
import_table_WCGHSL
import_table_WWCGHSL
import_table_YWCRWSL
import_table_GHHRWZS
import_table_YWCGHRWZS
import_table_GHRWWCL
import_table_ZKDSL
"
#所执行的脚本学生层面
REPORT_STUDENT=qu_student_quality_report.sh
#所执行的脚本学生层面 （里面的方法）
SHELL_STUDENT="
Total_number_of_students_in_school
Total_number_of_boys
Total_number_of_girls
Sex_ratio
Total_planning
Planned_Quantity_Completed
Uncompleted_Planning_Quantity
Number_of_completed_tasks
Total_number_of_planning_tasks
Total_number_of_completed_planning_tasks
Total_number_of_completed_planning_tasks_rate
Number_of_Quality_Control_Points_at_Layer
"

#所执行的脚本教师层面
REPORT_TEACHER=qu_teacher_quality_report.sh
#所执行的脚本教师层面（里面的方法）
SHELL_TEACHER="
Total_number_of_students_in_school
Total_number_of_boys
Total_number_of_girls
Sex_ratio
Total_planning
Planned_Quantity_Completed
Uncompleted_Planning_Quantity
Number_of_completed_tasks
Total_number_of_planning_tasks
Total_number_of_completed_planning_tasks
Total_number_of_completed_planning_tasks_rate
Number_of_Quality_Control_Points_at_Layer
"

#日志路径
function getRunLogPath(){
    datetime=$(date --date "0 days ago" +%Y%m%d)
    if [ ! -d "./logs" ];then
        mkdir ./logs
    fi
    LOG_RUN_PATH=/root/etl/SXNYZY/Timing/qualityreport/logs/$0_${datetime}.log
}

function doconmand(){
    start=$(date +%s)
    #读取文件的每一行
	for comand in ${comands}
	do
		ps -ef|grep $comand|grep -v grep|cut -c 9-15|xargs kill -9
        sh $REPORT "${comand}"
        end=$(date +%s)
		 if [ $? -eq 0 ]; then
	    	echo " $comand succeed>>>  耗时$(( $end - $start ))s " >>  ${LOG_RUN_PATH} 2>&1
		 else
		    echo " $comand failed>>>  耗时$(( $end - $start ))s "  >>  ${LOG_RUN_PATH} 2>&1;
		    echo " ## sh $comand 脚本执行错误，退出命令  exit 1  ##"  >>  ${LOG_RUN_PATH} 2>&1;
		    exit 1;
		 fi

	done
	end=$(date +%s)
	echo " 耗时$(( $end - $start ))s" >>  ${LOG_RUN_PATH} 2>&1
	#删除脚本执行过程中产生的Java文件
	rm -rf *.java
}


#学院层面
function docollege() {
   echo "-------学院层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_COLLEGE[*]}
   REPORT=${REPORT_COLLEGE}
   doconmand
}

#课程层面
function docourse() {
   echo "-------课程层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_COURSE[*]}
   REPORT=${REPORT_COURSE}
   doconmand
}

function domajor() {
   echo "-------专业层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_MAJOR[*]}
   REPORT=${REPORT_MAJOR}
   doconmand
}

function dostudent() {
   echo "-------学生层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_STUDENT[*]}
   REPORT=${REPORT_STUDENT}
   doconmand
}

function doteacher() {
   echo "-------教师层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_TEACHER[*]}
   REPORT=${REPORT_TEACHER}
   doconmand
}

getRunLogPath
echo "日志路径:"$LOG_RUN_PATH
currentPath=/root/etl/SXNYZY/QualityReport
echo "脚本路径:"$currentPath
comands=()
comands_twos=()


if [ $? -eq 0 ]; then
	cd  $currentPath/college
	docollege
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/course
	docourse
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/major
	domajor
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/student
	dostudent
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/teacher
	doteacher
fi

echo "*********所有脚本执行完毕*********" >>  ${LOG_RUN_PATH} 2>&1

